package com.pcbly.web.action.system;

import java.util.Date;
import java.util.List;

import com.pcbly.web.action.BaseAction;
import com.pcbly.web.bean.system.DepartBean;
import com.pcbly.web.bean.system.DepartChildBean;
import com.pcbly.web.business.depart.DepartService;

public class DepartAction extends BaseAction<DepartBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -892825914673745708L;

	private DepartService departService;

	private DepartBean departBean;

	private List<DepartBean> departBeans;

	private List<DepartChildBean> departChildBeans;

	public String index() throws Exception {
		departChildBeans = departService.findDepartChildBeansByParentId("1");
		return super.index();
	}

	public List<DepartChildBean> getDepartChildBeans() {
		return departChildBeans;
	}

	public void setDepartChildBeans(List<DepartChildBean> departChildBeans) {
		this.departChildBeans = departChildBeans;
	}

	public String dwrSave(DepartBean bean) throws Exception {
		try {
			if (bean.getId() == null || "".equals(bean.getId())) {
				bean.setRecycled("0");
				bean.setCreateUserId(getDwrUserId());
				bean.setCreateDate(new Date());
				departService.saveDepartBean(bean);
			} else {
				departService.updateDepartBean(bean);
			}
			super.dwrBaseSave(bean.getId());

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			return ERROR;
		}
	}

	public String dwrDelete(String id) throws Exception {
		departService.deleteDepartBeanById(id);
		super.dwrBaseDelete(id);
		return "ok";
	}

	public DepartBean dwrView(String id) throws Exception {
		departBean = departService.getDepartBeanById(id);
		super.dwrBaseView(id);
		return departBean;
	}

	public DepartBean getDepartBean() {
		return departBean;
	}

	public void setDepartBean(DepartBean departBean) {
		this.departBean = departBean;
	}

	public List<DepartBean> getDepartBeans() {
		return departBeans;
	}

	public void setDepartBeans(List<DepartBean> departBeans) {
		this.departBeans = departBeans;
	}

	public void setDepartService(DepartService departService) {
		this.departService = departService;
	}

}
